#ifndef WIDGETREGISTRY_H
#define WIDGETREGISTRY_H

#include <QWidget>
#include <QMap>
#include <QString>
#include <QVariant>

namespace dynamic_json_ui {

struct JsonUiElement;

class WidgetRegistry
{
public:
    static WidgetRegistry &instance();

    void registerWidget(const QString &id, QWidget *widget);
    QWidget *getWidget(const QString &id);

    template <typename T>
    T *getWidgetAs(const QString &id)
    {
        return qobject_cast<T *>(registry.value(id));
    }

private:
    QMap<QString, QWidget *> registry;
    WidgetRegistry() {}
};

} // namespace dynamic_json_ui

#endif // WIDGETREGISTRY_H
